
using QdbUnit;
using Mono.Cecil;

namespace QdbTool.Tests.TA
{
	internal class TAEnsureQdbReferenceIsAdded : TATestCaseBase
	{
		public void Test()
		{
			AssemblyDefinition assembly = GenerateAssembly("QdbReferenceSubject");

			Assert.IsFalse(FindQdbReference(assembly), "Qdb is already referenced");

			InstrumentAssembly(assembly);

			Assert.IsTrue(FindQdbReference(assembly), "Qdb must have been added.");
		}

		private bool FindQdbReference(AssemblyDefinition assembly)
		{
			foreach (ModuleDefinition module in assembly.Modules)
			{
				foreach (AssemblyNameReference reference in module.AssemblyReferences)
				{
					if (reference.Name == "Qdb") return true;
				}
			}

			return false;
		}
	}
}
